import { generateUniqueId } from "utils/utils";
import { ActionBase, ActionBaseOfCreep } from "../ActionBase";
import { priority } from "utils/constants/definetypes";

 
/**
 *  清理lab
 */
export class ActionClearLab  extends ActionBase<IActionCMD<"clearLab">>
{
    public execute(action: IActionCMD<"clearLab">): ActionCode 
    {
       
        const room = action.arg.entity as Required<Room>;
        if(!room)
        {
            return 0;
        }
        const transportparam:ITransportItem[]=[];
        const push_param=(from:StructureLab,to:  AnyStoreStructure,ResourceType:ResourceConstant,amount:number)=>
        {

            const item :ITransportItem={From: _.assign(from.pos,{id:from.id}),To:
            _.assign(to.pos,{id:to.id}),amount:amount,resourceType:ResourceType};
            transportparam.push(item);
        }
        action.arg.labs.forEach(e=>
            {
                if(e.mineralType)
                {
                    push_param(e,action.arg.store,e.mineralType,e.store.getUsedCapacity(e.mineralType))
                }
                else
                {
                    global.Log.Error(`添加lab出错`);
                }
            });
            
        const Taskarg:ICreepTaskData<"transportAccurate"> = 
        {
            type: "transportAccurate",
            arg: {
                List: transportparam
            },
            creeps: [],
            room:room.name,
            body: {},
            income: -1,
            required: [
                [['carry'], 1,1]
            ],
            cost:50
        }
        const task :ITask=
        {
            id:action.arg.transportid,
            ttl:5000,
            priority:action.priority,
            type:"creep",
            data:Taskarg,
            shard:1,
        }
        if(room.addNewTask(task))
        {
            //action.arg.onComplete();
        }
        return 0;
    }
}